using SimpleFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace SimpleFramework
{
    public class HotupSystem : TSingleton<HotupSystem>
    {
        private HotupContext m_Context = new HotupContext();
        private HotupState[] m_States = new HotupState[5];
        private HotupState m_Current;

        public UnityEvent<HotupStateId> StateChanged { get { return m_Context.StateChanged; } }
        public UnityEvent<ulong, ulong> ProgressHandler { get { return m_Context.ProgressHandler; } }
        public UnityEvent<string> Complete { get { return m_Context.Complete; } }

        public HotupSystem()
        {
            m_States[0] = new HotupCheckState(m_Context);
            m_States[1] = new HotupLoadAssetState(m_Context);
            m_States[2] = new HotupReplaceState(m_Context);
            m_States[3] = new HotupRestartState(m_Context);
            m_States[4] = new HotupFailureState(m_Context);
        }

        public void Reset()
        {
            m_Context.Reset();
        }

        public void Update()
        {
            if (m_Current != null)
                m_Current.OnUpdate();
        }

        public void Change(HotupStateId id)
        {
            if (m_Current != null)
                m_Current.OnExit();
            m_Current = m_States[(int)id];
            m_Current.OnEnter();
            m_Context.StateChanged.Invoke(id);
        }

        public void Clear()
        {
            Debug.Log("HotUpdate.Clear");
        }
    }
}

